package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.CarNoStatVo;
import com.ruoyi.system.mapper.TzCarIoLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TzCarInfoMapper;
import com.ruoyi.system.domain.TzCarInfo;
import com.ruoyi.system.service.ITzCarInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 车牌信息Service业务层处理
 * 
 * @author lmj
 * @date 2024-12-07
 */
@Service
public class TzCarInfoServiceImpl implements ITzCarInfoService 
{
    @Autowired
    private TzCarInfoMapper tzCarInfoMapper;
    @Autowired
    private TzCarIoLogMapper tzCarIoLogMapper;

    /**
     * 查询车牌信息
     * 
     * @param id 车牌信息主键
     * @return 车牌信息
     */
    @Override
    public TzCarInfo selectTzCarInfoById(Long id)
    {
        return tzCarInfoMapper.selectTzCarInfoById(id);
    }

    /**
     * 查询车牌信息列表
     * 
     * @param tzCarInfo 车牌信息
     * @return 车牌信息
     */
    @Override
    public List<TzCarInfo> selectTzCarInfoList(TzCarInfo tzCarInfo)
    {
        List<TzCarInfo> list = tzCarInfoMapper.selectTzCarInfoList(tzCarInfo);
        for(TzCarInfo car : list){
            CarNoStatVo map = tzCarIoLogMapper.selectLastTimeCount(car.getCarNo(), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, car.getBeginDate()));
            if(map.getIoNum()!=null){
                car.setIoNum(map.getIoNum());
            }
            if(map.getTotalTime()!=null){
                car.setTotalTime(DateUtils.singleTimeLabel(map.getTotalTime()));
            }
        }
        return list;
    }

    /**
     * 新增车牌信息
     * 
     * @param tzCarInfo 车牌信息
     * @return 结果
     */
    @Override
    public int insertTzCarInfo(TzCarInfo tzCarInfo)
    {
        tzCarInfo.setCreateTime(DateUtils.getNowDate());
        return tzCarInfoMapper.insertTzCarInfo(tzCarInfo);
    }

    /**
     * 修改车牌信息
     * 
     * @param tzCarInfo 车牌信息
     * @return 结果
     */
    @Override
    public int updateTzCarInfo(TzCarInfo tzCarInfo)
    {
        tzCarInfo.setUpdateTime(DateUtils.getNowDate());
        return tzCarInfoMapper.updateTzCarInfo(tzCarInfo);
    }

    /**
     * 批量删除车牌信息
     * 
     * @param ids 需要删除的车牌信息主键
     * @return 结果
     */
    @Override
    public int deleteTzCarInfoByIds(String ids)
    {
        return tzCarInfoMapper.deleteTzCarInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除车牌信息信息
     * 
     * @param id 车牌信息主键
     * @return 结果
     */
    @Override
    public int deleteTzCarInfoById(Long id)
    {
        return tzCarInfoMapper.deleteTzCarInfoById(id);
    }
}
